const CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {
  productionSourceMap: false,
  transpileDependencies: ['element-ui', 'ele-admin', 'vue-i18n'],

  // 开发服务器配置
  devServer: {
    // 禁用缓存，避免git pull后出现缓存问题
    headers: {
      'Cache-Control': 'no-cache, no-store, must-revalidate',
      'Pragma': 'no-cache',
      'Expires': '0'
    }
  },

  chainWebpack: (config) => {
    config.resolve.alias.set('vue$', 'vue/dist/vue.esm.js');
    config.plugins.delete('prefetch');

    // 开发环境禁用缓存
    // if (process.env.NODE_ENV === 'development') {
    //   config.output.filename('[name].js?t=[chunkhash]');
    //   config.output.chunkFilename('[name].js?t=[chunkhash]');
    // }

    if (process.env.NODE_ENV === 'development') {
      config.output.filename('[name].js');
      config.output.chunkFilename('[name].js');
    }

    if (process.env.NODE_ENV !== 'development') {
      // 对超过10kb的文件gzip压缩
      config.plugin('compressionPlugin').use(new CompressionWebpackPlugin({
        test: /\.(js|css|html)$/,
        threshold: 10240
      }));
    }
  },
  css: {
    loaderOptions: {
      sass: {
        sassOptions: {
          outputStyle: 'expanded'
        }
      }
    }
  }
}
